﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using EntityModels;
using BusinessLayer;
using System.Data.Entity;

namespace PresentationLayer
{
    public partial class NewTemplate : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User u = GetUserFromCookie();
            if (u != null)
            {
                UserFullName.InnerText = u.firstname + " " + u.lastname;
            }
        }
        protected void Logout_Click(object sender, EventArgs e)
        {
            HttpCookie myCookie = new HttpCookie("eventnet");
            myCookie.Expires = DateTime.Now.AddDays(-1d);
            Response.Cookies.Add(myCookie);

            Response.Redirect("Default.aspx");
        }

        protected void CheckCookie()
        {
            HttpCookie cookie = Request.Cookies["eventnet"];
            if (cookie == null)
            {
                Response.Redirect("Default.aspx");
            }
        }

        protected User GetUserFromCookie()
        {
            HttpCookie cookie = Request.Cookies["eventnet"];
            if (cookie == null)
            {
                Response.Redirect("Default.aspx");
            }
            else
            {
                String uname = cookie["eventnet-username"];
                return Controller.Instance.GetUser(uname);
            }
            return null;
        }

        public HtmlGenericControl BodyTag
        {
            get
            {
                return MasterPageBodyTag;
            }
            set
            {
                MasterPageBodyTag = value;
            }
        }

        public int test;
    }
}